package cn.jufuns.db;

import java.io.IOException;
import java.util.Properties;
import org.springframework.core.io.Resource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

public class ConnectionProperty {
	private static Log log = LogFactory.getLog(ConnectionProperty.class);
	private String driverClassName;
	private String user;
	private String password;
	private String url;
	private boolean showsql = true;
	private boolean showjvm;

	public String getDriverClassName() {
		return driverClassName;
	}

	public void setDriverClassName(String driverClassName) {
		this.driverClassName = driverClassName;
	}

	public String getUser() {
		return user;
	}

	public void setUser(String user) {
		this.user = user;
	}

	public String getPassword() {
		return password;
	}

	public void setPassword(String password) {
		this.password = password;
	}

	public String getUrl() {
		return url;
	}

	public void setUrl(String url) {
		this.url = url;
	}

	public boolean isShowsql() {
		return showsql;
	}

	public void setShowsql(boolean showsql) {
		this.showsql = showsql;
	}

	public boolean isShowjvm() {
		return showjvm;
	}

	public void setShowjvm(boolean showjvm) {
		this.showjvm = showjvm;
	}

	 public ConnectionProperty(String driverClassName, String user, String password, String url)
	    {
	        this.driverClassName = driverClassName;
	        this.user = user;
	        this.password = password;
	        this.url = url;
	    }

	    public ConnectionProperty(String driverClassName, String user, String password, String url, boolean showsql, boolean showjvm)
	    {
	        this.driverClassName = driverClassName;
	        this.user = user;
	        this.password = password;
	        this.url = url;
	        this.showsql = showsql;
	        this.showjvm = showjvm;
	    }

	    public ConnectionProperty(Resource resource)
	    {
	        if(resource == null)
	            throw new RuntimeException("resource is null");
	        Properties properties = null;
	        try
	        {
	            java.io.InputStream inStream = resource.getInputStream();
	            properties = new Properties();
	            properties.load(inStream);
	        }
	        catch(IOException e)
	        {
	            throw new ExceptionInInitializerError(e);
	        }
	        driverClassName = properties.getProperty("jdbc.driverClassName");
	        user = properties.getProperty("jdbc.user");
	        password = properties.getProperty("jdbc.password");
	        url = properties.getProperty("jdbc.url");
	        showsql = Boolean.valueOf(properties.getProperty("jdbc.showsql")).booleanValue();
	        showjvm = Boolean.valueOf(properties.getProperty("jdbc.showjvm")).booleanValue();
	    }

}
